import Vue from "vue";
import Router from "vue-router";
// import index from '@/components/index'
import loginpage from "../views/loginpage/loginemail";
import index from "../views/index";
import register from "../views/loginpage/register";
import seckillIndex from "../views/seckillpage/index";
// import adminIndex from "../views/adminpage/index";

import manageUser from '@/views/adminpage/ManageUser'
import ManageOrder from "@/views/adminpage/ManageOrder";
import adminIndex from "../views/adminpage/aboutview";

import adminLogin from "../views/adminpage/login";
import seckillOrders from "../views/seckillpage/seckillOrders";

import goods from "../views/goods";

import manage from '@/views/adminpage/Manage'
import edit from "@/views/adminpage/edituser"

import orders from '@/views/orders.vue'

Vue.use(Router);

const router = new Router({
  mode: "history",
  routes: [
    {
      path: "/orders",
      name: "orders",
      component: orders,
      meta: {
        title: "订单历史记录"
      }
    },
    {
      path: "/seckillpage/seckillOrders",
      name: "seckillOrders",
      component: seckillOrders,
      meta: {
        title: "秒杀订单历史记录"
      }
    },
    {
      path: "/",
      redirect:"index"
    },
    {
      path: "/goods",
      component:goods
    },
   
    {
      path: "/index",
      name: "index",
      component: index,
      meta: {
        title: "商城首页"
      }
    },
    {
      path: "/loginpage/loginemail",
      name: "loginpage",
      component: loginpage,
      meta: {
        title: "邮箱登录页面"
      }
    },
    {
      path: "/loginpage/register",
      name: "register",
      component: register,
      meta: {
        title: "注册页面"
      }
    },
    {
      path: "/seckillpage/index",
      name: "seckillIndex",
      component: seckillIndex,
      meta: {
        title: "秒杀页面"
      }
    },
    // {
    //   path: "/adminpage/index",
    //   name: "adminIndex",
    //   component: adminIndex,
    //   meta: {
    //     title: "后台管理页面"
    //   }
    // },
     {
      path: "/adminpage/index",
      name: "adminIndex",
      component: adminIndex,
      meta: {
        title: "后台管理页面"
      }
    },
    {
      path: "/adminpage/login",
      name: "adminLogin",
      component: adminLogin,
      meta: {
        title: "后台登录页面"
      }
    },
    {
      path: "/edituser",
      component:edit,
      meta: {
        title: "用户信息管理页面"
      }
    },
    {path:"/goodsManage",component:manage},
    {path:"/user",component:manageUser},
    {path:"/order",component:ManageOrder},
  ]
});

export default router;

// router.beforeEach((to, from, next) => {
//   // 1.如果访问的是登录页面（无需权限），直接放行
//   if (
//     to.path === '/' ||
//     to.path === '/index' ||
//     to.path === '/loginpage/loginemail' ||
//     to.path === '/loginpage/register' ||
//     to.path === '/adminpage/login' 
//   )
//     return next();
//   // 2.如果访问的是有登录权限的页面，先要获取token
//   const tokenStr = window.localStorage.getItem("x-access-token");
//   // 2.1如果token为空，强制跳转到登录页面；否则，直接放行
//   if (!tokenStr&&to.path!='/adminpage/index') {
//     alert("您还未登录!请先登录")
//     return next("/loginpage/loginemail");
//   }else if(!tokenStr&&to.path==='/adminpage/index'){
//     alert("您还未登录!请先登录")
//     return next("/adminpage/login");
//   }
//   next();
// });
